<template>
  <div class="back">
    <span class="icon" @click="handleGoBack">
      <i class="iconfont iconstbar_fanhui"></i>
    </span>
    <span>返回</span>
  </div>
</template>

<script>
import { mapGetters, mapMutations } from 'vuex'
export default {
  methods: {
    handleGoBack() {
      if (this.getCurrentCart.length) {
        // 点击返回清空购物车
        this.clearCart()
      } 
      // 点击返回unitPrice设置为2
      this.setUnitPrice(2)
      // 点击返回totalAmount设置为2
      this.setTotalAmount(0)
      this.clearLotteryState()
      console.log(this.$route)
      if (this.$route.matched[0].path == '/select-number') {
        this.$router.push({path: '/'})
      } else {
        this.$router.go(-1)
      }
    },
    ...mapMutations('lottery', {
      clearCart: 'CLEAR_CART',
      setUnitPrice: 'SET_UNIT_PRICE',
      setTotalAmount: 'SET_TOTAL_AMOUNT',
      clearLotteryState: 'CLEAR_STATE'

    })
  },
  computed: {
    ...mapGetters('lottery', ['getCurrentCart', 'getCurrentLotteryState'])
  }
}
</script>

<style lang="stylus" scoped>
@import '~@/assets/styles/mixins.styl'
.back 
  display flex   
  align-items center
  .icon 
    extend-click()
    .iconfont 
      font-size 22px
     
</style>